package com.admin.service.impl;

import com.admin.entity.Apk;
import com.admin.entity.SystemApk;
import com.admin.mapper.SystemApkMapper;
import com.admin.service.ISystemApkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@Service
public class SystemApkServiceImpl extends ServiceImpl<SystemApkMapper, SystemApk> implements ISystemApkService {
    @Autowired
    private SystemApkMapper systemApkMapper;

    /**
     * 查询系统apk升级包同时搜索应用名称
     * @param page
     * @param limit
     * @param apkName
     * @return
     */
    public IPage SearchSystemApk(int page, int limit, String apkName) {
        Page serach = new Page(page, limit);
        QueryWrapper q = new QueryWrapper();

        if (apkName != null && apkName != "") {
            q.like("system_apk_name", apkName);
        }
        IPage result = systemApkMapper.selectPage(serach, q);
        return result;
    }

    /**
     * 查询所有系统apk并分页
     * @param page
     * @param limit
     * @param systemApkName
     * @return
     */
    public IPage searchSystemApkWithPage(int page, int limit, String systemApkName) {
        Page serach = new Page(page, limit);
        QueryWrapper q = new QueryWrapper();

        if (systemApkName != null && systemApkName != "") {
            q.like("system_apk_name", systemApkName);
        }
        IPage result = systemApkMapper.selectPage(serach, q);
        return result;
    }

    /**
     * 新增系统apk应用
     * @param systemApk
     * @return
     */
    public int addSystemApk(SystemApk systemApk)
    {
        int insert = systemApkMapper.insert(systemApk);
        return insert;
    }

    /**
     * 查询MD5判断应用是否重复
     * @param systemApkMd5
     * @return
     */
    public SystemApk selectSystemApkMd5AndApkAdmin (String systemApkMd5)
    {
        QueryWrapper q=new QueryWrapper();
        q.eq("system_apk_md5",systemApkMd5);
        SystemApk systemApk=systemApkMapper.selectOne(q);
        return systemApk;
    }
}
